<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn"  uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${pageContext.request.contextPath }/intranet/js/text.readonly.true.js"></script>
<style type="text/css">
	.coun_sal_find, .coun_pro_find{
		text-align: right;
	}
	.cwe_select{text-align: center;}
	
	.coun_save div{
		vertical-align: middle;
	}
	.coun_save div p{
		display: inline-block;
		vertical-align: middle;
		padding-left: 30px;
	}
	.coun_pro_info, .coun_sal_info{
		display: table;
		width: 100%;
		border: 3px solid gray;
		padding-top: 5px;
		padding-left: 5px;
		padding-right: 5px;
		margin-bottom: 10px;
	}
	.coun_pro_info div, .coun_sal_info div{
		display: table-row;
	}
	.coun_pro_info div div, .coun_sal_info div div{
		border: 1px solid gray;
		display: inline-block;
	}
	.coun_sal_info div div{width: 25%;}
	.coun_pro_info div div{width: 25%;}
	.coun_pro_info div div p, .coun_sal_info div div p{
		display: table-cell;
		height: 30px;
		vertical-align: middle;
		width: 40%;
	}
	.coun_pro_info div div p:FIRST-CHILD, .coun_sal_info div div p:FIRST-CHILD{
		background-color: #eeeeee;
		text-align: center;
		border-right: 1px solid gray;
	}
	.coun_pro_info div div p:LAST-CHILD, .coun_sal_info div div p:LAST-CHILD{
		padding: 5px;
	}
	.coun_bottom{width: 100%;}
	.coun_bottom div{
		vertical-align: middle;
	}
	.coun_bottom div p{
		vertical-align: middle;
	}
	.cl_select2{width: 160px; text-align: center;}
</style>
<script type="text/javascript">
$(window).on('load', function () {
	$( ".cwe_select" ).selectpicker({
		style: 'btn-info',
		"width" : "150px"
	});
	$( ".cl_select2" ).selectpicker({
		style: 'btn-info'
	}); 
	readOnly();
	
	if("${dto.ct_ing}" == "01" || "${dto.ct_ing}" == "05"){
		$( "#cs_loan" ).spinner({
		      min: 100,
		      max: document.getElementById("cs_max").value.replace('만원',''),
		      step: 100,
		      start: 100
		      //numberFormat: "C"
		 });
	}
	
	var ing = document.getElementById("ct_ing").options;
	for(var i=0; ing.length; i++){
		if(ing[i].value == '${dto.ct_ing}'){
			$( "#ct_ing" ).selectpicker('val',ing[i].value);//seleted
			if(ing[i].value !='01' && ing[i].value !='05'){
				document.getElementById("btnEdit").disabled='disabled';
				//document.getElementById("cs_loan").disabled='disabled';
				document.getElementById("cs_content").disabled='disabled';
				document.getElementById("btnSal").disabled='disabled';
				document.getElementById("btnPro").disabled='disabled';
				document.getElementById("proNO").disabled='disabled';
				//$( "#ct_ing" ).selectpicker('setStyle','btn-danger'); 셀렉트박스 스타일 변경
				$( "#ct_ing" ).prop('disabled',true);
				$( "#ct_ing" ).selectpicker('refresh');
			}
		}
		if(ing[i].value !='' && ing[i].value !='01' && ing[i].value != '${dto.ct_ing}'){
			//alert(ing[i].text+"/"+ing[i].value+'/ ${dto.ct_ing} /'+i + "/" + ing.length);
			$( "#ct_ing" ).find('[value='+ing[i].value+']').remove();//option 제거
			$( "#ct_ing" ).selectpicker('refresh');
			i--;//option이 제거되면 ing.length -1됨으로 i도 -1해줌
		}
	}
});


function fnProSearch() {
	var pd_no = document.getElementById("proNO").value.trim();
	if(pd_no == ""){
		alert("상품 번호를 입력해주세요!");
		document.getElementById("proNO").value = "";
		document.getElementById("proNO").focus();
		return;
	}
	var url = "${pageContext.request.contextPath}/Coun/SPSearch.clamp";
	var params = "pd_no="+pd_no;
	$.ajax({
		type: 'POST',
		url: url,
		data:  params,
		success: function(html){
			$("#coun_pro_info").html(html);
			var no = document.getElementById("pro_no").value;
			if(no == "") alert("검색하신 상품 정보가 없습니다!");
			readOnly();
		}
	});
}

function fnSub() {
	if("${sessionScope.mid}" != "${dto.rg_pp}"){
		alert("담당자만 수정할 수 있습니다!");
		return false;
	}
	
	var frm = document.getElementById("frm");
	
	if(frm.pro_nm.value == ""){
		alert("상품 정보를 검색 해주세요~");
		return false;
	}
	if(frm.pro_yn.value == "N"){
		alert("사용하실수 없는 상품 정보 입니다!");
		return false;
	}
	if(frm.cs_content.value == ""){
		alert("상담 내용을 입력 해주세요~");
		return false;
	}
	
	document.getElementById("pd_no").value = frm.pro_no.value;
	document.getElementById("pd_rate").value = frm.pro_rate.value;
	document.getElementById("pd_pback").value = frm.pro_pback.value;
	document.getElementById("pd_prd").value = frm.pro_prd.value;
	
	var cMax = document.getElementById("cs_max").value;
	var pMax = frm.pro_max.value.replace("만원","");
	var pMin = frm.pro_min.value.replace("만원","");
	var loan = document.getElementById("cs_loan").value;
	pMax = pMax.replace(",","");
	pMin = pMin.replace(",","");
	if(pMax == "1억원") pMax = "10000";
	cMax = Number(cMax);
	pMax = Number(pMax);
	pMin = Number(pMin);
	loan = Number(loan);
	
	if(loan == 0){
		alert("대출 신청액을 입력해주세요!");
		return false;
	}
	if(cMax<loan){
		alert("대출한도 초과 금액은 신청하실 수 없습니다!");
		return false;
	}else{
		if(pMax<loan){
			alert("상품 최대한도 초과 금액은 신청하실 수 없습니다!");
			return false;
		}
		if(pMin>loan){
			alert("상품 최저한도 미만 금액은 신청하실 수 없습니다!");
			return false;
		}
	}
	
	var flag = confirm("정말 수정 하시겠습니까?");
	if(flag){
		frm.action ="${pageContext.request.contextPath }/Coun/CounEditOK.clamp";
		frm.submit();
		return true;
	}
	else return false;
}

function fnGoList() {
	var list = document.getElementById("list");
	list.submit();
}

function keyevent() {
	if(event.keyCode == 13){
		fnProSearch();
	}
}

</script>
</head>
<body>
	<div align="center">
		<form action="#" id="frm" name="frm" method="post">
			<input type="hidden" id="cs_no" name="cs_no" value="${dto.cs_no }">
			<input type="hidden" id="pd_no" name="pd_no" value="">
			<input type="hidden" id="pd_pback" name="pd_pback" value="">
			<input type="hidden" id="pd_rate" name="pd_rate" value="">
			<input type="hidden" id="pd_prd" name="pd_prd" value="">
			<div style="width: 1200px;">
				<h1 align="center">상담 상세보기<small>Counsel View</small></h1>
				<div class="coun_sal_find">
					<p>
						<label class="label label-danger" style="font-size: 13pt;">사원번호</label>
						&nbsp;&nbsp;&nbsp;
						<input type="text" class="form-control input-sm" style="width: auto; display: inline-block;" value="${dto.sa_no }">
						&nbsp;&nbsp;&nbsp;
						<input type="button" id="btnSal" value="조회" class="btn btn-success">
					</p>
				</div>
				<div class="coun_sal_info">
					<div>
						<div>
							<p>사원번호</p>
							<p><input type="text" class="rotrue" value="${dto.sa_no }"></p>
						</div>
						<div>
							<p>이 름</p>
							<p><input type="text" value="${dto.sa_nm }"></p>
						</div>
						<div>
							<p>나 이</p>
							<p><input type="text" value="${dto.sa_age }"></p>
						</div>
						<div>
							<p>성 별</p>
							<p><input type="text" value="${dto.sa_sx }"></p>
						</div>
					</div>
					<div>
						<div>
							<p>부 서</p>
							<c:forEach items="${sadps}" var="sadp">
								<c:if test="${sadp.cd_grp2 eq dto.sa_dpm}">
									<p><input type="text" value="${sadp.cd_grp2_nm }"></p>
								</c:if>
							</c:forEach>
						</div>
						<div>
							<p>직 책</p>
							<c:forEach items="${psts}" var="pst">
								<c:if test="${pst.cd_grp2 eq dto.sa_gd}">
									<p><input type="text" value="${pst.cd_grp2_nm }"></p>
								</c:if>
							</c:forEach>
						</div>
						<div>
							<p>주택소유</p>
							<p><input type="text" value="${dto.sa_home }"></p>
						</div>
						<div>
							<p>차량소유</p>
							<p><input type="text" value="${dto.sa_car }"></p>
						</div>
					</div>
					<div>
						<div>
							<p>입사일</p>
							<p><input type="text" value="${fn:substring(dto.sa_hd,0,10) }"></p>
						</div>
						<div>
							<p>연 봉</p>
							<p><input type="text" value="${dto.cs_loan }만원"></p>
						</div>
						<div>
							<p>결혼여부</p>
							<p><input type="text" value="${dto.sa_marr }"></p>
						</div>
						<div>
							<p>대출한도</p>
							<p><input type="text" id="cs_max" name="cs_max" value="${dto.cs_max }만원"></p>
						</div>
					</div>
				</div>
				<div class="coun_pro_find">
					<p>
						<label class="label label-danger" style="font-size: 13pt;">상품번호</label>
						&nbsp;&nbsp;&nbsp;
						<input type="search" id="proNO" class="form-control input-sm" style="width: auto; display: inline-block;" value="${dto.pd_no }" onkeyup="keyevent()">
						&nbsp;&nbsp;&nbsp;
						<input type="button" id="btnPro" value="조회" class="btn btn-success" onclick="fnProSearch()">
					</p>
				</div>
				<div id="coun_pro_info" class="coun_pro_info">
					<div>
						<div>
							<p>상품번호</p>
							<p><input type="text" id="pro_no" name="pro_no" value="${dto.pd_no }"></p>
						</div>
						<div>
							<p>상품명</p>
							<p><input type="text" id="pd_nm" name="pro_nm" value="${dto.pd_nm }"></p>
						</div>
						<div>
							<p>상환방법</p>
							<p><input type="text" id="pd_pback" name="pro_pback" value="${dto.pd_pback }"></p>
						</div>
						<div>
							<p>금리</p>
							<p><input type="text" id="pd_rate" name="pro_rate" value="${dto.pd_rate }"></p>
						</div>
					</div>
					<div>
						<div>
							<p>상환 기간</p>
							<p><input type="text" id="pd_prd" name="pro_prd" value="${dto.pd_prd }"></p>
						</div>
						<div>
							<p>최저한도</p>
							<p><input type="text" name="pro_min" value="${dto.pd_min }"></p>
						</div>
						<div>
							<p>최대한도</p>
							<p><input type="text" name="pro_max" value="${dto.pd_max }"></p>
						</div>
						<div>
							<p>상품 상태</p>
							<p><input type="text" id="pd_yn" name="pro_yn" value="${dto.pd_yn }"></p>
						</div>
					</div>
				</div>
				
				<div class="coun_save">
					<div style="display: inline-block;">
						<p><label class="label label-danger" style="font-size: 13pt;">비 고</label></p>
						<p><textarea id="cs_content" name="cs_content" rows="3" cols="95" style="resize: none;">${dto.cs_content }</textarea></p>
					</div>
					<div style="display: inline-block;">
						<p><label class="label label-danger" style="font-size: 13pt;">신청액 (단위:만원)</label></p>
						<p>
							<input type="number" id="cs_loan" name="cs_loan" value="${dto.cs_loan }" readonly="readonly">
						</p>
					</div>
					<div class="coun_bottom">
						<div style="display: inline-block; width: 57%" align="left">
							<p><label class="label label-danger" style="font-size: 13pt;">계약 상태</label></p>
							<p>
								<select id="ct_ing" name="ct_ing" class="cl_select2 input-sm  col-lg-3">
									<option value="">계약상태</option>
									<!-- <option data-divider="true"></option> -->
										<c:forEach items="${ctings }" var="cting" varStatus="loop">
											<option value="${cting.cd_grp2 }">${cting.cd_grp2_nm }</option>
										</c:forEach>
								</select>
							</p>
							<p><label class="label label-danger" style="font-size: 13pt;">상담 담당자</label></p>
							<p><input type="text" id="rg_pp" name="rg_pp" value="${dto.rg_pp_nm }(${dto.rg_pp })" style="display: inline-block;"> </p>
						</div>
						<div style="display: inline-block; width: 40%" align="right">
							<p>
								<input type="button" id="btnEdit" value="상담수정" class="btn btn-primary" onclick="return fnSub()">
								&nbsp;&nbsp;&nbsp;
								<input type="button" value="목록" class="btn btn-primary" onclick="fnGoList()">
							</p>
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
	<form action="${pageContext.request.contextPath}/Coun/CounList.clamp" method="post" id="list" name="list">
		<input type="hidden" name="list" value="list">
	</form>
</body>
</html>